package com.myflink.day03;

import org.apache.flink.api.common.serialization.SimpleStringSchema;
import org.apache.flink.streaming.api.datastream.DataStreamSink;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.connectors.kafka.FlinkKafkaProducer011;

/**
 * @author Shelly An
 * @create 2020/9/18 11:13
 */
public class Sink_Kafka {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);

        //环境来产生数据流
        DataStreamSource<String> fileDS = env.readTextFile("input/sensor-data.log");

        //数据流来调用sink
        DataStreamSink<String> kafkaDS = fileDS.addSink(new FlinkKafkaProducer011<String>(
                "hadoop102:9092,hadoop103:9092,hadoop104:9092",
                "sensor",
                new SimpleStringSchema()
        ));

        env.execute();
    }
}
